﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SPSIndia.XSLDemo
{
    public class PretendAnnouncementsCollection
    {

        private List<PretendAnnouncement> allAnnouncements;

        public PretendAnnouncementsCollection() 
        { allAnnouncements = new List<PretendAnnouncement>(); }

        public void GenerateTestData()
        {
            // Imagine that we're really connected to an SPList rather than hard coding.
            allAnnouncements.Add(
                new PretendAnnouncement("SharePoint Saturday - The Conference", "Washington, DC", "<a target=_new href='http://www.spstc.org'>Click here to view the event details.</a>"));

            allAnnouncements.Add(
                new PretendAnnouncement("SharePoint Saturday India", "Virtual Event", "<a target=_new href='http://www.sharepointsaturday.org/india/default.aspx'>Click here to view the event details.</a>"));

            allAnnouncements.Add(
                new PretendAnnouncement("BrightStarr Cookout", "New Jersey, USA", "BrightStarr is holding its annual summer cookout."));
            
            allAnnouncements.Add(
                new PretendAnnouncement("Test Announcement", "Test location", "This is a test announcements."));
        }

        public string PretendAnnouncementsAsXmlString {
            get
            {
                StringBuilder theXml = new StringBuilder();

                theXml.Append("<AllPretendAnnouncements Count=\"");
                theXml.Append(allAnnouncements.Count);
                theXml.Append("\">");

                foreach (PretendAnnouncement pa in allAnnouncements)
                {
                    theXml.Append(pa.PretendAnnouncementAsXmlString);
                }

                theXml.Append("</AllPretendAnnouncements>");

                return theXml.ToString();
            } // get

        } // PretendAnnouncementsAsXml property

        // An individual announcements
        class PretendAnnouncement
        {
            string myTitle;
            string myLocation;
            string myDescription;

            public PretendAnnouncement(string theTitle, string theLocation, string theDescription) {
                myTitle = theTitle;
                myLocation = theLocation;
                myDescription = theDescription;    
            }

            public string PretendAnnouncementAsXmlString {
                get {

                    StringBuilder meAsXmlText = new StringBuilder();

                    meAsXmlText.Append("<AnAnnouncement>");
                    
                    meAsXmlText.Append("<title>");
                    meAsXmlText.Append(myTitle);
                    meAsXmlText.Append("</title>");
                    
                    meAsXmlText.Append("<location>");
                    meAsXmlText.Append(myLocation);
                    meAsXmlText.Append("</location>");

                    meAsXmlText.Append("<description><![CDATA[");
                    meAsXmlText.Append(myDescription);
                    meAsXmlText.Append("]]></description>");

                    meAsXmlText.Append("</AnAnnouncement>");

                    return meAsXmlText.ToString();

                } // get
            } // MyXslAsText

        } // class PretendAnnouncement;

    } // PretendAnnouncementsCollection

} // namespace
